﻿@model PagedList<MeterInfo>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>无标题文档</title>
    <link href="/css/style.css" rel="stylesheet" type="text/css" />
    <link href="/css/select.css" rel="stylesheet" type="text/css" />
    <link href="/css/frominfostyle.css" rel="stylesheet" type="text/css" />
    <script type="text/javascript" src="/js/jquery.js"></script>
    <script src="/js/jquery.form.js"></script>
    <script type="text/javascript" src="/js/jquery.idTabs.min.js"></script>
    <script type="text/javascript" src="/js/select-ui.min.js"></script>
    <script src="/js/dateFormat.js"></script>
    <script language="javascript">
        $(function () {
            //导航切换
            $(".imglist li").click(function () {
                $(".imglist li.selected").removeClass("selected")
                $(this).addClass("selected");
            })
        })
    </script>
    <script type="text/javascript">

        function Search(obj) {
            $form1 = $('#form1');
            var customerId = $form1.find("[name='userId']").val();
            $.post('/user/FindByCustomerId', { customerId: customerId }, function (data) {
                if (data.Succeed) {
                    $form1.find("[name='CustomerName']").val(data.Obj.Name);
                    $form1.find("[name='WaterTypeId']").val(data.Obj.WaterTypeName);
                    $form1.find("[name='MeterNo']").val(data.Obj.MeterNo);
                    $form1.find("[name='FirstArea']").val(data.Obj.FirstArea);
                    $form1.find("[name='SecondArea']").val(data.Obj.SecondArea);
                    $form1.find("[name='DetailAddress']").val(data.Obj.DetailAddress);
                    $form1.find("[name='ParentId']").val(data.Obj.EmployeeName);
                    $form1.find("[name='MeterNature']").val(data.Obj.MeterNature);
                    $form1.find("[name='CreateDate']").val(data.Obj.CreateDate);
                    $form1.find("[name='CustomerId']").val(data.Obj.Id);
                }
                else {
                    window.alert("指定编号的用户不存在！");
                }
            }, 'json')
        }


        function Search1(obj) {
            $form1 = $('#form2');
            var customerId = $form1.find("[name='userId']").val();
            $.post('/user/FindByCustomerId', { customerId: customerId }, function (data) {
                if (data.Succeed) {
                    $form1.find("[name='CustomerName']").val(data.Obj.Name);
                    $form1.find("[name='WaterTypeId']").val(data.Obj.WaterTypeName);
                    $form1.find("[name='MeterNo']").val(data.Obj.MeterNo);
                    $form1.find("[name='FirstArea']").val(data.Obj.FirstArea);
                    $form1.find("[name='SecondArea']").val(data.Obj.SecondArea);
                    $form1.find("[name='DetailAddress']").val(data.Obj.DetailAddress);
                    $form1.find("[name='ParentId']").val(data.Obj.EmployeeName);
                    $form1.find("[name='MeterNature']").val(data.Obj.MeterNature);
                    $form1.find("[name='CreateDate']").val(data.Obj.CreateDate);
                    $form1.find("[name='CustomerId']").val(data.Obj.Id);
                }
                else {
                    window.alert("指定编号的用户不存在！");
                }
            }, 'json')
        }




        $(document).ready(function () {

            var api = {
                edit: "/meter/MeterEdit",
                del: "/meter/MeterDel"
            }
            $('#form1').attr('action', api.edit);
            $('#form2').attr('action', api.edit);




            $(".click").click(function () {
                $(".tip").fadeIn(200);
            });

            $(".tiptop a").click(function () {
                $(".tip").fadeOut(200);
            });

            $(".sure").click(function () {
                $(".tip").fadeOut(100);
            });

            $(".cancel").click(function () {
                $(".tip").fadeOut(100);
            });

            //用户添加
            $(".clicka").click(function () {
                $(".tipa").fadeIn(200);
            });
            $(".tiptopa a").click(function () {
                $(".tipa").fadeOut(200);
            });

            $(".surea").click(function () {
                $(".tipa").fadeOut(100);
            });


            $(".cancela").click(function () {
                $(".tipa").fadeOut(100);
            });

            //抄表添加
            $(".clickfromadd").click(function () {
                $(".tipfromadd").fadeIn(200);
            });

            $(".tiptopfromadd a").click(function () {
                $(".tipfromadd").fadeOut(200);
            });

            $(".surefromadd").click(function () {

                $('#form1').ajaxSubmit({
                    success: function (data) {
                        if (data.Succeed) {
                            window.location.reload();
                        } else {
                            alert(data.Msg);
                        }
                    }
                })

            });

            $(".cancelfromadd").click(function () {
                $(".tipfromadd").fadeOut(100);
            });



            $(".clickfrommodify").click(function () {
                var count = $("input:checked").length;
                if (count < 1) {
                    alert("至少选择一项进行修改！");
                }
                else if (count > 1) {
                    alert("只能选择一项进行修改！");
                }
                else {
                    $(".tipfrommodify").fadeIn(200);
                    var jsonModel = $("input:checked").parents('tr').attr('jsonModel');
                    var model = $.parseJSON(jsonModel); 
                    $('#form2').find("[name='userId']").val(model.CustomerMap.CustomerId).attr("readonly", "readonly");
                    Search1();

                    $('#form2').find("input[name='Id']").val(model.Id);
                    $('#form2').find("input[name='CustomerId']").val(model.CustomerId); 
                    $('#form2').find("input[name='LastShow']").val(model.LastShow);

                    $('#form2').find("input[name='ThisShow']").val(model.ThisShow);
                    $('#form2').find("input[name='ThisLoseWater']").val(model.ThisLoseWater); 


                    var date = new Date(model.ReadMeterDate);
                    var formatDate = date.format("yyyy/MM/dd");


                    $('#form2').find("select[name='ReadMeterDate']").find("option[value='" + formatDate + "']").attr("selected", true);
                    $('#form2').find("select[name='ReadMeterDate']").prev().find("em:first").text($('#form2').find("select[name='ReadMeterDate']").find("option:selected").text());

                    $('#form2').find("select[name='MeterStat']").find("option[value='" + model.MeterStat + "']").attr("selected", true);
                    $('#form2').find("select[name='MeterStat']").prev().find("em:first").text($('#form2').find("select[name='MeterStat']").find("option:selected").text());
                     
                }


            });

            $(".tiptopfrommodify a").click(function () {
                $(".tipfrommodify").fadeOut(200);
            });

            $(".surefrommodify").click(function () {
                $('#form2').ajaxSubmit({
                    success: function (data) {
                        if (data.Succeed) {
                            window.location.reload();
                        } else {
                            alert(data.Msg);
                        }
                    }
                }) 
            });

            $(".cancelfrommodify").click(function () {
                $(".tipfrommodify").fadeOut(100);
            });


            //删除用户
            $(".clickdel").click(function (del) {
                 
                var count = $("input:checked").length;
                if (count < 1) {
                    alert("至少选择一项进行修改！");
                }
                else if (count > 1) {
                    alert("只能选择一项进行修改！");
                }
                else {
                    $(".tipdel").fadeIn(200); 
                }
                 
            });

            $(".tiptopdel a").click(function (del) {
                $(".tipdel").fadeOut(200);
            });

            $(".suredel").click(function (del) { 
                $obj = $("input:checked").parents("tr");
                $.post(api.del, { id: $obj.find("input:checked").val() }, function (data) {
                    $(".tipdel").fadeOut(100);
                    window.location.reload();
                }, 'json') 

            });

            $(".canceldel").click(function (del) {
                $(".tipdel").fadeOut(100);
            });


            //抄表入库
            $(".clickin").click(function (del) {
                $(".tipin").fadeIn(200);
            });

            $(".tiptopin a").click(function (del) {
                $(".tipin").fadeOut(200);
            });

            $(".surein").click(function (del) {
                $(".tipin").fadeOut(100);
            });

            $(".cancelin").click(function (del) {
                $(".tipin").fadeOut(100);
            });


        });
    </script>
    <script type="text/javascript">
        $(document).ready(function (e) {
            $(".select1").uedSelect({
                width: 345
            });
            $(".select2").uedSelect({
                width: 167
            });
            $(".select3").uedSelect({
                width: 150
            });
        });
    </script>
</head>
<body>
    <div class="place">
        <span>位置：</span>
        <ul class="placeul">
            <li><a href="#">首页</a></li>
            <li><a href="#">抄表管理</a></li>
            <li><a href="#">抄表添加</a></li>
        </ul>
    </div>
    <div class="rightinfo">
        <div class="tools">
            <ul class="toolbar">
                <li class="clickfromadd"><span><img src="/images/t01a.png" /></span>添加</li>
                <li class="clickfrommodify"><span><img src="/images/t02.png" /></span>修改</li>
                <li class="clickdel"><span><img src="/images/t03.png" /></span>删除</li>
                <li class="clickin"><span><img src="/images/t03.png" /></span>抄表入库</li>
            </ul>

        </div>
        <table class="imgtable">
            <thead>
                <tr>
                    <th>选择</th>
                    <th>用户编号</th>
                    <th>用户姓名</th>
                    <th>区域分布</th>
                    <th>区域名称</th>
                    <th>详细地址</th>
                    <th>用水类别</th>
                    <th>上期底数</th>
                    <th>本期底数</th>
                    <th>用量</th>
                    <th>水损</th>
                    <th>抄表人员</th>
                    <th>抄表日期</th>
                </tr>
            </thead>
            <tbody>
                @foreach (var item in Model)
                {
                    <tr jsonModel="@(JsonConvert.SerializeObject(item))">
                        <td><input name="" type="checkbox" value="@(item.Id)" /></td>
                        <td>@(item.Customer?.CustomerId)</td>
                        <td height="30px;">@item.Customer.CustomerName</td>
                        <td><a href="#">@item.Customer.FirstArea</a></td>
                        <td>@item.Customer.SecondArea</td>
                        <td>@item.Customer.DetailAddress</td>
                        <td>@item.Customer.WaterType.TypeName</td>
                        <td>@(item.LastShow)</td>
                        <td>@(item.ThisShow)</td>
                        <td>@(item.ThisShow - item.LastShow)</td>
                        <td>@(item.ThisLoseWater)</td>
                        <td>@(item.Customer.EmployeeInfo?.NAME)</td>
                        <td>@(item.ReadMeterDate.ToString("yyyy/MM/dd"))</td>
                    </tr>
                }

            </tbody>
        </table>
        <div class="pagin">
            <div class="message">共<i class="blue">@(Model.TotalItemCount)</i>条记录，共&nbsp;<i class="blue">@(Model.TotalPageCount)&nbsp;</i>页</div>
            @Html.Pager(Model, BaseController.PagerOptions)
        </div>

        <form id="form1" method="post">
            <!--抄表添加-->
            <div class="tipfromadd">
                <div class="tiptopfromadd"><img src="/images/t06.png" /><span>抄表添加</span><a></a></div>
                <div class="tipinfofromadd">
                    <div class="userinfozbfromadd">
                        <dt class="userinfozbtitfromadd">抄表信息</dt>
                        <ul class="seachform" id="addUl">
                            <li>
                                <label>用户编号</label>
                                <input name="userId" type="text" class="scinput" onblur="Search()" />
                            </li>
                            <li>
                                <label>上期底数</label>
                                <input name="LastShow" type="text" class="scinput" />
                            </li>
                            <li>
                                <label>本期底数</label>
                                <input name="ThisShow" type="text" class="scinput" />
                            </li>
                            <li>
                                <label>本期水损</label>
                                <input name="ThisLoseWater" type="text" class="scinput" />
                            </li>
                            <li>
                                <label>抄表日期</label>
                                <div class="vocation">
                                    <select class="select3" name="ReadMeterDate">
                                        @{
                                            var dateStart1 = DateTime.Now.AddDays(-DateTime.Now.Day).AddDays(1);
                                            var dateEnd1 = DateTime.Now.AddMonths(1).AddDays(-DateTime.Now.Day);
                                            var tempDate1 = dateStart1;
                                        }
                                        @while (tempDate1 >= dateStart1 && tempDate1 <= dateEnd1)
                                        {
                                        <option value="@(tempDate1.ToString("yyyy/MM/dd"))">@tempDate1.ToString("yyyy年MM月dd日")</option>
                                            tempDate1 = tempDate1.AddDays(1);
                                        }
                                    </select>
                                </div>
                            </li>

                            <li>
                                <label>水表状态</label>
                                <div class="vocation">
                                    <select class="select3" name="MeterState">
                                        <option value="0">正常</option>
                                        <option value="1">欠费</option>
                                    </select>
                                </div>
                            </li>
                        </ul>
                    </div>
                    <div class="tiprightfromadd">
                        <dt class="userinfotitfromadd">用户信息</dt>
                        <ul class="seachform" id="userInfoUl">
                            <li>
                                <label>用户姓名</label>
                                <input name="CustomerName" type="text" class="scinput" disabled="disabled" style="background:#EFEFEF" />
                            </li>
                            <li>
                                <label>用水类型</label>
                                <input name="WaterTypeId" type="text" class="scinput" disabled="disabled" style="background:#EFEFEF" />
                            </li>
                            <li>
                                <label>水表编号</label>
                                <input name="MeterNo" type="text" class="scinput" disabled="disabled" style="background:#EFEFEF" />
                            </li>

                            <li>
                                <label>区域分布</label>
                                <input name="FirstArea" type="text" class="scinput" disabled="disabled" style="background:#EFEFEF" />
                            </li>
                            <li>
                                <label>区域名称</label>
                                <input name="SecondArea" type="text" class="scinput" disabled="disabled" style="background:#EFEFEF" />
                            </li>
                            <li>
                                <label>详细地址</label>
                                <input name="DetailAddress" type="text" class="scinput" disabled="disabled" style="background:#EFEFEF" />
                            </li>

                            <li>
                                <label>抄表人员</label>
                                <input name="ParentId" type="text" class="scinput" disabled="disabled" style="background:#EFEFEF" />
                            </li>
                            <li>
                                <label>用户性质</label>
                                <input name="MeterNature" type="text" class="scinput" disabled="disabled" style="background:#EFEFEF" />
                            </li>
                            <li>
                                <label>建档日期</label>
                                <input name="CreateDate" type="text" class="scinput" disabled="disabled" style="background:#EFEFEF" />
                            </li>

                        </ul>
                    </div>
                </div>
                <div class="tipbtnfromadd">
                    @Html.Hidden("CustomerId", "")
                    @Html.Hidden("Id", "0")
                    <input name="" type="button" class="surefromadd" value="添加" />
                    &nbsp;
                    <input name="" type="button" class="cancelfromadd" value="取消" />
                </div>
            </div>
        </form>

        <!--删除用户-->
        <div class="tipdel">
            <div class="tiptopdel"><span>提示信息</span><a></a></div>
            <div class="tipinfodel">
                <span><img src="/images/ticon01.png" /></span>
                <div class="tiprightdel">
                    <p>确定要删除用户的抄表记录吗？</p>
                    <cite>如果是请点击确定按钮 ，否则请点取消。</cite>
                </div>
            </div>
            <div class="tipbtndel">
                <input name="" type="button" class="suredel" value="确定" />
                &nbsp;
                <input name="" type="button" class="canceldel" value="取消" />
            </div>
        </div>

        <!--抄表入库-->
        <div class="tipin">
            <div class="tiptopin"><span>提示信息</span><a></a></div>
            <div class="tipinfoin">
                <span><img src="/images/ticon01.png" /></span>
                <div class="tiprightin">
                    <p>确定要把所选用户的抄表数据加入到抄表总数据中吗？</p>
                    <p>该操作不可逆请慎用？</p>
                    <cite>如果是请点击确定按钮 ，否则请点取消。</cite>
                </div>
            </div>
            <div class="tipbtnin">
                <input name="" type="button" class="surein" value="确定" />
                &nbsp;
                <input name="" type="button" class="cancelin" value="取消" />
            </div>
        </div>


        <form id="form2" method="post">

            <!--抄表修改用户-->
            <div class="tipfrommodify">
                <div class="tiptopfrommodify"><img src="/images/t06.png" /><span>抄表修改</span><a></a></div>
                <div class="tipinfofrommodify">
                    <div class="userinfozbfrommodify">
                        <dt class="userinfozbtitfrommodify">抄表信息</dt>
                        <ul class="seachform">

                            <li>
                                <label>用户编号</label>
                                <input name="userId" type="text" class="scinput" onblur="Search()" />
                            </li>
                            <li>
                                <label>上期底数</label>
                                <input name="LastShow" type="text" class="scinput" />
                            </li>
                            <li>
                                <label>本期底数</label>
                                <input name="ThisShow" type="text" class="scinput" />
                            </li>
                            <li>
                                <label>本期水损</label>
                                <input name="ThisLoseWater" type="text" class="scinput" />
                            </li>
                            <li>
                                <label>抄表日期</label>
                                <div class="vocation">
                                    <select class="select3" name="ReadMeterDate">
                                        @{
                                            var dateStart2 = DateTime.Now.AddDays(-DateTime.Now.Day).AddDays(1);
                                            var dateEnd2 = DateTime.Now.AddMonths(1).AddDays(-DateTime.Now.Day);
                                            var tempDate2 = dateStart2;
                                        }
                                        @while (tempDate2 >= dateStart2 && tempDate2 <= dateEnd2)
                                        {
                                            <option value="@(tempDate2.ToString("yyyy/MM/dd"))">@tempDate2.ToString("yyyy年MM月dd日")</option>
                                            tempDate2 = tempDate2.AddDays(1);
                                        }
                                    </select>
                                </div>
                            </li>

                            <li>
                                <label>水表状态</label>
                                <div class="vocation">
                                    <select class="select3" name="MeterState">
                                        <option value="0">正常</option>
                                        <option value="1">欠费</option>
                                    </select>
                                </div>
                            </li>




                        </ul>
                    </div>
                    <div class="tiprightfrommodify">
                        <dt class="userinfotitfrommodify">用户信息</dt>
                        <ul class="seachform">
                            <li>
                                <label>用户姓名</label>
                                <input name="CustomerName" type="text" class="scinput" disabled="disabled" style="background:#EFEFEF" />
                            </li>
                            <li>
                                <label>用水类型</label>
                                <input name="WaterTypeId" type="text" class="scinput" disabled="disabled" style="background:#EFEFEF" />
                            </li>
                            <li>
                                <label>水表编号</label>
                                <input name="MeterNo" type="text" class="scinput" disabled="disabled" style="background:#EFEFEF" />
                            </li>

                            <li>
                                <label>区域分布</label>
                                <input name="FirstArea" type="text" class="scinput" disabled="disabled" style="background:#EFEFEF" />
                            </li>
                            <li>
                                <label>区域名称</label>
                                <input name="SecondArea" type="text" class="scinput" disabled="disabled" style="background:#EFEFEF" />
                            </li>
                            <li>
                                <label>详细地址</label>
                                <input name="DetailAddress" type="text" class="scinput" disabled="disabled" style="background:#EFEFEF" />
                            </li>

                            <li>
                                <label>抄表人员</label>
                                <input name="ParentId" type="text" class="scinput" disabled="disabled" style="background:#EFEFEF" />
                            </li>
                            <li>
                                <label>用户性质</label>
                                <input name="MeterNature" type="text" class="scinput" disabled="disabled" style="background:#EFEFEF" />
                            </li>
                            <li>
                                <label>建档日期</label>
                                <input name="CreateDate" type="text" class="scinput" disabled="disabled" style="background:#EFEFEF" />
                            </li>

                        </ul>
                    </div>
                </div>
                <div class="tipbtnfrommodify">
                    @Html.Hidden("CustomerId", "")
                    @Html.Hidden("Id", "0")
                    <input name="" type="button" class="surefrommodify" value="确定" />
                    &nbsp;
                    <input name="" type="button" class="cancelfrommodify" value="取消" />
                </div>
            </div>
        </form>
        <script type="text/javascript">
            $('.tablelist tbody tr:odd').addClass('odd');
        </script>
    </div>
</body>
</html>
